package ue.client.entities;

import java.util.ArrayList;

import ue.client.core.Vector2d;
import ue.client.core.Vector2i;

public abstract class Entity {
	
	public static ArrayList<Entity> entities = new ArrayList<Entity>();
	
	private static int lastID = 0;
	
	protected final int ID;
	
	protected Vector2d pos;
	protected Vector2i size;
	
	public Entity(Vector2d pos, Vector2i size) {
		this.pos = pos;
		this.size = size;
		
		ID = lastID++;
	}
	
	public Vector2d getPos() {
		return pos;
	}

	public void setPos(Vector2d pos) {
		this.pos = pos;
	}
	
	public Vector2i getSize() {
		return size;
	}

	public void setSize(Vector2i size) {
		this.size = size;
	}

	public int getID() {
		return ID;
	}
	
	//STATIC METHODS
	public static int addEntity(Entity entity) {
		Entity tmp = getEntity(entity.getID());
		if(tmp == null) {
			entities.add(entity);
			return entity.getID();
		}
		return tmp.getID();
	}
	
	public static void removeEntity(int ID) {
		for (int i = 0; i < entities.size(); i++) {
			if (entities.get(i).getID() == ID) {
				entities.remove(i);
				return;
			}
		}
		return;
	}
	
	public static Entity getEntity(int ID) {
		for (int i = 0; i < entities.size(); i++) {
			if (entities.get(i).getID() == ID)
				return entities.get(i);
		}
		return null;
	}
}
